package com.douglas.managesystem.service.student.impl;

import com.douglas.managesystem.common.SearchEntity;
import com.douglas.managesystem.dao.student.ClassMapper;
import com.douglas.managesystem.dao.student.LessonMapper;
import com.douglas.managesystem.entity.studentpojo.Classpojo;
import com.douglas.managesystem.entity.studentpojo.Lesson;
import com.douglas.managesystem.service.student.ClassService;
import com.douglas.managesystem.service.student.LessonService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description 班级业务实现
 * @Author 以梦为馬 <Douglas1314@126.com>
 * @Version V1.0.0
 * @Date 2020-11-20 00:07:49
 **/
@SuppressWarnings("all")
@Service
public class ClassServiceImpl implements ClassService {


    @Autowired
    private ClassMapper classMapper;


    /**
     * 1.分页查询所有班级
     * @param params
     * @return
     */
    @Override
    public PageInfo<Classpojo> findAllClassByPage(SearchEntity params) {
        if(params.getPageNum() == null || params.getPageNum() == 0) {
            params.setPageNum(1);
        }
        if(params.getPageSize() == null || params.getPageSize() == 0) {
            params.setPageSize(10);
        }
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        List<Classpojo> lessons = classMapper.findAllClassByPage(params.getEntity());

        PageInfo<Classpojo> page = new PageInfo<Classpojo>(lessons);
        return page;
    }


    /**
     * 2.新增班级
     * @param classpojo
     */
    @Override
    public void saveClassPo(Classpojo classpojo) {
        Classpojo classpoDb = classMapper.queryClassPoByClassId(classpojo.getClassId());
        if(classpoDb != null){
            return;
        }
        classMapper.insert(classpojo);
    }

    /**
     * 3.更新班级
     * @param classpojo
     */
    @Override
    public void updateClassPo(Classpojo classpojo) {
        classMapper.update(classpojo);
    }

    /**
     * 4.根据id查询班级对象
     * @param id
     * @return
     */
    @Override
    public Classpojo findClassPoById(String id) {
        return classMapper.queryClassPoById(id);
    }

    /**
     * 5.根据id删除
     * @param id
     */
    @Override
    public void delete(String id) {
        classMapper.delete(id);
    }

    /**
     * 6.查询所有班级id的集合
     * @return
     */
    @Override
    public List<String> queryAllClassList() {
        return classMapper.queryAllClassList();
    }
}
